enterprsie_research_store = Ext.extend(Ext.data.GroupingStore, {
	constructor : function() {
		// this.cfg = _cfg;
		enterprsie_research_store.superclass.constructor.call(this, {
			proxy : new Ext.data.HttpProxy({
				url : 'cxxqysjsb/enterprise_research_/getallenterprsie_reaearch.action?id='
						+ userId,// 用户的ID
				method : 'post'
			}),
			autoLoad : true,
			sortInfo : {
				field : 'research_year',
				direction : "DESC"
			},
			groupField : 'research_year',
			reader : new Ext.data.JsonReader({
						fields : ['research_id', 'enterprise_id', 'editable',
								'research_is_new', 'reaearch_type',
								'research_check_pass', 'research_name',
								'research_persons', 'research_built_date',
								'research_built_type',
								'research_authentication_type', 'research_year']
					})
		})
	}
});
enterprsie_base_info_grid = Ext.extend(Ext.grid.GridPanel, {
	store : null,
	addnewwin : null,
	editwin : null,
	constructor : function() {
		this.addnewwin = new addenterprsie_research_formpanel_win();
		this.store = new enterprsie_research_store();
		enterprsie_base_info_grid.superclass.constructor.call(this, {
			loadMask : {
				msg : '数据加载中...'
			},
			title : '企业基本情况-企业研发机构',
			iconCls : 'SMLPoolManage_sml',
			sm : arrsm,
			frame : true,
			view : new Ext.grid.GroupingView({
				forceFit : true,
				groupTextTpl : '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "条数据" : "条数据"]})'
			}),
			cm : new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
						header : 'ID',
						width : 10,
						dataIndex : 'research_id',
						id : 'research_id',
						hidden : true,
						align : 'center'
					}, {
						header : '企业编号',
						width : 10,
						dataIndex : 'enterprise_id',
						id : 'enterprise_id',
						hidden : true,
						sortable : false,
						align : 'center'
					}, {
						header : '年度',
						width : 100,
						dataIndex : 'research_year',
						id : 'research_year',
						renderer : this.getYearN,
						sortable : false,
						align : 'center'
					}, {
						header : '机构类型',
						width : 100,
						dataIndex : 'research_built_type',
						sortable : false,
						renderer : this.getenterprise_research_organizatiovalueinner,
						align : 'center'
					}, {
						header : '名称',
						width : 120,
						dataIndex : 'research_name',
						sortable : false,
						align : 'center'
					}, {
						header : '人数',
						width : 80,
						dataIndex : 'research_persons',
						sortable : false,
						align : 'center'
					}, {
						header : '建立时间',
						width : 120,
						dataIndex : 'research_built_date',
						sortable : false,
						id : 'research_built_date',
						align : 'center'
					}, {
						header : '认证情况',
						width : 200,
						dataIndex : 'research_authentication_type',
						renderer : this.getAuTypeName,
						id : 'research_authentication_type',
						align : 'center'
					}, {
						header : '类型',
						width : 100,
						dataIndex : 'reaearch_type',
						renderer : this.getTypeName,
						id : 'reaearch_type',
						align : 'center'
					}, {
						header : '审核状态',
						width : 100,
						dataIndex : 'research_check_pass',
						renderer : this.getCheckTypeName,
						id : 'research_check_pass',
						align : 'center'
					}]),
			autoExpandColumn : 'research_check_pass',
			tbar : [{
				text : '增加<font color="red">' + OPTION_NDDECLARE_YEAR + '年'
						+ getDataType(OPTION_DATA_TYPE) + '</font>研究机构数据',
				scope : this,
				iconCls : 'itemadd',
				handler : function() {
					this.addnewwin.show(Ext.getDom('login-view'));
				}
			}, '-', {
				text : '修改',
				scope : this,
				tooltip : '只允许修改草稿数据',
				iconCls : 'smlEdit_edit',
				handler : function() {
					var ro = this.getSelectionModel().getSelected();
					if (!ro) {
						Ext.Msg.show({
									title : '提示',
									msg : '没有选择数据',
									icon : Ext.MessageBox.ERROR,
									buttons : Ext.MessageBox.OK
								});
						return;
					} else {
						var research_check_pass = ro.get('research_check_pass');
						if (research_check_pass == 0) {
							Ext.Msg.show({
										title : '提示',
										msg : '正在审核数据不能修改',
										icon : Ext.MessageBox.ERROR,
										buttons : Ext.MessageBox.OK
									});
							return;
						} else if (research_check_pass == 1
								|| research_check_pass == 2) {
							Ext.Msg.show({
										title : '提示',
										msg : '审核完成数据不能修改',
										icon : Ext.MessageBox.ERROR,
										buttons : Ext.MessageBox.OK
									});
							return;
						} else {
							var eid = ro.get('enterprise_id');
							var rid = ro.get('research_id');
							var year = ro.get('research_year');
							var research_built_type = ro
									.get('research_built_type');
							var research_name = ro.get('research_name');
							var research_persons = ro.get('research_persons');
							var research_built_date = ro
									.get('research_built_date');
							var research_authentication_type = ro
									.get('research_authentication_type');
							var reaearch_type = ro.get('reaearch_type');
							var cfg = {
								eid : eid,
								rid : rid,
								year : year,
								research_built_type : research_built_type,
								research_name : research_name,
								research_persons : research_persons,
								research_built_date : research_built_date,
								research_authentication_type : research_authentication_type,
								reaearch_type : reaearch_type
							}
							this.editwin = new editenterprsie_research_formpanel_win(cfg);
							this.editwin.show(Ext.getDom('login-view'));
							this.editwin.on('editok', function() {
										this.getStore().reload()
									}, this);
						}
					}
				}
			}, '-', {
				text : '刷新',
				scope : this,
				iconCls : 'refreshtty',
				handler : function() {
					this.getStore().reload();
				}
			}]

		});
		this.addnewwin.on('addok', function() {
					this.getStore().reload();
				}, this);
	},
	getYearN : function(value) {
		return value + '年';
	},
	getenterprise_research_organizatiovalueinner : function(value) {
		return getenterprise_research_organizatiovalue(value);
	},
	getTypeName : function(code) {
		getDataType
		return '<font color="red">' + getDataType(code) + "</font>";
	},
	getAuTypeName : function(code) {
		return getenterprise_research_authenticationvalue(code);
	},
	getCheckTypeName : function(code) {
		return getCheckResultName(code);
	}
});
addenterprsie_research_formpanel = Ext.extend(Ext.form.FormPanel, {
	constructor : function() {
		addenterprsie_research_formpanel.superclass.constructor.call(this, {
					frame : true,
					height : 190,
					bodyStyle : 'padding: 10px 0px 0 10px;',
					labelWidth : 80,
					labelAlign : 'right',
					defaults : {
						anchor : '95%',
						allowBlank : true,
						msgTarget : 'side'
					},
					items : [{
								xtype : 'hidden',
								name : 'userid',
								value : userId
							}, {
								xtype : 'textfield',
								fieldLabel : '申报年度',
								anchor : '99%',
								name : 'type',
								readOnly : true,
								disabled : true,
								value : OPTION_NDDECLARE_YEAR + '年'
										+ getDataType(OPTION_DATA_TYPE) + ''
							}, {
								xtype : 'combo',
								fieldLabel : '类型',
								hiddenName : 'research_built_type',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								store : enterprise_research_organization_combox,
								emptyText : '请选择类型',
								allowBlank : false,
								blankText : '请选择类型'
							}, {
								xtype : 'textfield',
								fieldLabel : '机构名称',
								name : 'research_name',
								allowBlank : false,
								blankText : '机构名称不能为空',
								anchor : '99%'
							}, {
								xtype : 'textfield',
								fieldLabel : '机构人数',
								name : 'research_persons',
								regex : /^[0-9]+$/,
								allowBlank : false,
								blankText : '机构人数不能为空',
								anchor : '99%'
							}, {
								xtype : 'datefield',
								fieldLabel : '建立时间',
								name : 'research_built_date',
								allowBlank : false,
								blankText : '建立时间不能为空',
								anchor : '99%'
							}, {
								xtype : 'combo',
								fieldLabel : '认证情况',
								hiddenName : 'research_authentication_type',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								store : enterprise_research_authentication_combox,
								emptyText : '认证情况',
								allowBlank : false,
								blankText : '请选择认证情况'
							}]
				})
	}
})
/**
 * 增加一条新的数据
 * 
 * @class addenterprsie_research_formpanel_win
 * @extends Ext.Window
 */
addenterprsie_research_formpanel_win = Ext.extend(Ext.Window, {
	panel : null,
	constructor : function() {
		this.panel = new addenterprsie_research_formpanel();
		addenterprsie_research_formpanel_win.superclass.constructor.call(this,
				{
					width : 500,
					title : '申报<font color="red">' + OPTION_NDDECLARE_YEAR
							+ '年' + getDataType(OPTION_DATA_TYPE) + '</font>数据',
					iconCls : 'itemadd',
					// layout : 'form',
					closeAction : 'hide',
					frame : true,
					modal : true,
					plain : true,
					items : this.panel,
					buttons : [{
								text : '保存草稿',
								scope : this,
								iconCls : 'itemadd',
								handler : this.submit
							}, {
								text : '取消',
								scope : this,
								iconCls : 'cancel',
								handler : function() {

									this.hide()
								}
							}]
				});
		this.addEvents('addok');
	},
	submit : function() {
		var form = this.panel.getForm();
		if (form.isValid()) {
			var uid = userId;
			var year = OPTION_NDDECLARE_YEAR;
			var type = OPTION_DATA_TYPE;
			var research_built_type = form.findField('research_built_type')
					.getValue();
			var research_name = form.findField('research_name').getValue();
			var research_persons = form.findField('research_persons')
					.getValue();
			var research_built_date = form.findField('research_built_date')
					.getValue();
			var research_authentication_type = form
					.findField('research_authentication_type').getValue();
			Ext.Ajax.request({
				url : 'cxxqysjsb/enterprise_research_/insertnewenterpriseresearchdata.action?',
				params : {
					uid : uid,
					year : year,
					type : type,
					research_built_type : research_built_type,
					research_name : research_name,
					research_persons : research_persons,
					research_built_date : research_built_date,
					research_authentication_type : research_authentication_type
				},
				scope : this,
				success : function(response, options) {
					if (response.responseText == 'ok') {
						this.fireEvent('addok');
						this.hide();
					} else if (response.responseText == 'fail') {
						Ext.Msg.show({
									title : '提示',
									msg : '数据传输失败',
									icon : Ext.Msg.WARNING,
									buttons : Ext.Msg.OK
								});
						return;
					}else if(response.responseText == 'already'){
					Ext.Msg.show({
									title : '提示',
									msg : '数据已添加，请勿重复添加',
									icon : Ext.Msg.WARNING,
									buttons : Ext.Msg.OK
								});
						return;
					}
				}
			});

		} else {
			Ext.Msg.show({
						title : '提示',
						msg : '请正确填写数据',
						icon : Ext.Msg.WARNING,
						buttons : Ext.Msg.OK
					});
			return;
		}
	}
})
/**
 * 修改数据
 * 
 * @class editenterprsie_research_formpanel
 * @extends Ext.form.FormPanel
 */
editenterprsie_research_formpanel = Ext.extend(Ext.form.FormPanel, {
	cfg : null,
	constructor : function(_cfg) {
		this.cfg = _cfg;
		editenterprsie_research_formpanel.superclass.constructor.call(this, {
					frame : true,
					height : 190,
					bodyStyle : 'padding: 10px 0px 0 10px;',
					labelWidth : 80,
					labelAlign : 'right',
					defaults : {
						anchor : '95%',
						allowBlank : true,
						msgTarget : 'side'
					},
					items : [{
								xtype : 'hidden',
								name : 'rid',
								value : this.cfg.rid
							}, {
								xtype : 'hidden',
								name : 'eid',
								value : this.cfg.eid
							}, {
								xtype : 'combo',
								fieldLabel : '类型',
								hiddenName : 'research_built_type',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								value : this.cfg.research_built_type,
								store : enterprise_research_organization_combox,
								emptyText : '请选择类型',
								allowBlank : false,
								blankText : '请选择类型'
							}, {
								xtype : 'textfield',
								fieldLabel : '机构名称',
								name : 'research_name',
								allowBlank : false,
								value : this.cfg.research_name,
								blankText : '机构名称不能为空',
								anchor : '99%'
							}, {
								xtype : 'textfield',
								fieldLabel : '机构人数',
								name : 'research_persons',
								regex : /^[0-9]+$/,
								allowBlank : false,
								value : this.cfg.research_persons,
								blankText : '机构人数不能为空',
								anchor : '99%'
							}, {
								xtype : 'datefield',
								fieldLabel : '建立时间',
								value : this.cfg.research_built_date,
								name : 'research_built_date',
								allowBlank : false,
								blankText : '建立时间不能为空',
								anchor : '99%'
							}, {
								xtype : 'combo',
								fieldLabel : '认证情况',
								hiddenName : 'research_authentication_type',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								value : this.cfg.research_authentication_type,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								store : enterprise_research_authentication_combox,
								emptyText : '认证情况',
								allowBlank : false,
								blankText : '请选择认证情况'
							}]
				});
	}
});
editenterprsie_research_formpanel_win = Ext.extend(Ext.Window, {
	cfg : null,
	panel : null,
	constructor : function(_cfg) {
		this.cfg = _cfg;
		this.panel = new editenterprsie_research_formpanel(this.cfg);
		editenterprsie_research_formpanel_win.superclass.constructor.call(this,
				{
					width : 500,
					title : '修改<font color="red">' + this.cfg.year + '年'
							+ getDataType(this.cfg.reaearch_type) + '</font>数据',
					iconCls : 'configmanage',
					// layout : 'form',
					closeAction : 'hide',
					frame : true,
					modal : true,
					plain : true,
					items : this.panel,
					buttons : [{
								text : '修改草稿',
								scope : this,
								iconCls : 'itemadd',
								handler : this.submit
							}, {
								text : '取消',
								scope : this,
								iconCls : 'cancel',
								handler : function() {

									this.hide()
								}
							}]
				});
		this.addEvents('editok');
	},
	submit : function() {
		var form = this.panel.getForm();
		var rid = form.findField('rid').getValue();
		var eid = form.findField('eid').getValue();
		var research_built_type = form.findField('research_built_type')
				.getValue();
		var research_name = form.findField('research_name').getValue();
		var research_persons = form.findField('research_persons').getValue();
		var research_built_date = form.findField('research_built_date')
				.getValue();
		var research_authentication_type = form
				.findField('research_authentication_type').getValue();
		Ext.Ajax.request({
			url : 'cxxqysjsb/enterprise_research_/updateenterpriseresearchbyid.action?',
			scope : this,
			success : function(response, options) {
				if (response.responseText == 'ok') {
					this.fireEvent('editok');
					this.hide();
				}
			},
			params : {
				rid : rid,
				eid : eid,
				research_built_type : research_built_type,
				research_name : research_name,
				research_persons : research_persons,
				research_built_date : research_built_date,
				research_authentication_type : research_authentication_type
			}
		});
	}
})
/**
 * 总体组装面板
 * 
 * @class
 * @extends demo.module
 */
Ext.extend(demo.module, {
			init : function() {

				this.datareportreaearch = new enterprsie_base_info_grid();
				this.main.add(this.datareportreaearch);
				this.main.doLayout();
			}
		});